﻿using module .\Lib\UnitTest.psm1
using module .\CalcRunner.psd1
using module .\CalcRunner.psm1

class CalcRunnerTest : TestBase
{
    [SetUp()]
    [void]SetUp()
    {
        $this.target = [CalcRunner]::new();
        $this.target.TargetPath  = 'C:\KeywordAutoTest\02.AutoTest\01.TestTarget\CalcApp.exe';
        $this.target.LogFilePath = 'C:\KeywordAutoTest\02.AutoTest\02.Runner.ps\Test.log';
        Remove-item $this.target.LogFilePath -Force -ErrorAction Ignore
        $this.target.SetUp();
    }

    [TearDown()]
    [void]TearDown()
    {
        $this.target.TearDown();
    }

    [Test()]
    [void]結果取得テスト()
    {
        $result = $this.target.結果取得();
        $this.AssertEquals('計算結果:金額=[円]', $result );
    }

}

$error.Clear()
[void](([CalcRunnerTest]::new()).RunTest());
#スクリプトのエラー処理は、ここで行う必要がある
if( ( $error -ne $null ) -and ( $error.Count -ne 0 ) )
{
    $errFlag = $false
    foreach($err in $error)
    {
        if( $err.Exception.GetType().Name -ne 'UnitTestException' )
        {
            if( $errFlag -eq $false )
            {
                $errFlag = $true
                Write-host "`n*****Error info*****"
            }
            $err
        }
    }
}